<template>
  <div class="dlqsearch">
    <Form ref="formInline"
          :model="searchObj"
          inline>
      <FormItem prop="user">
        <Input type="text"
               v-if="searchType === '2'"
               v-model="searchObj.key"
               placeholder="单位名称">
        <Icon type="ios-search"
              slot="prepend"></Icon>
        </Input>
        <Input type="text"
               v-if="searchType !== '2'&&searchType !== '0'"
               v-model="searchObj.key"
               placeholder="姓名或身份证号">
        <Icon type="ios-search"
              slot="prepend"></Icon>
        </Input>

      </FormItem>
      <FormItem v-if="searchType !== '2'&&searchType !== '0'">
        <!-- 日期选择 -->
        <DatePicker type="daterange"
                    split-panels
                    placeholder="请选择日期"
                    @on-change="timeChange"></DatePicker>
      </FormItem>
      <FormItem>
        <Button style="margin-right: 10px"
                v-if="searchType !== '0'"
                type="primary"
                @click="search">查询</Button>
        <Button style="margin-right: 10px"
                v-if="searchType !== '0'&& aa==='0'"
                type="primary"
                @click="tianjia">添加</Button>
        <!--    <Button type="primary" @click="searchMoreAcion" v-if="searchMore === 'searchMore'">高级查询</Button>-->
        <Button style="margin-right: 10px"
                v-if="searchType !== '0'&& typea==='0'"
                type="primary"
                @click="apenda">添加</Button>
      </FormItem>
      <FormItem v-if="searchType !== '3'">
        <CheckboxGroup v-model="countryList"
                       @on-change="changeCountry"
                       style="margin-top:7px;margin-left:10px;">
          <Checkbox :indeterminate="indeterminate"
                    :value="checkAll"
                    @click.prevent.native="handleCheckAll">全市</Checkbox>
          <Checkbox label="市本级"
                    v-if="searchType === '1'||searchType === '2'">市本级</Checkbox>
          <Checkbox v-for="(item, index) in areaList"
                    :key="index"
                    :label="item.name"></Checkbox>
        </CheckboxGroup>
      </FormItem>
    </Form>
    <Modal width="1600px"
           v-model="modalb"
           title="修改">
      <Row>
        <i-Col span="2"
               style="margin-top: 5px;margin-left: 5px;text-align:right">姓名：</i-Col>
        <i-Col span="9">
          <Input v-model="name"
                 placeholder="请输入姓名"
                 style="width: 500px" />
          <span class="red">*</span>
        </i-Col>
        <i-Col span="3"
               style="margin-top: 5px;margin-left: 5px;text-align:right">所属国籍：</i-Col>
        <i-Col span="9"><Input v-model="nationality"
                 placeholder="请输入所属国籍"
                 style="width: 500px" /></i-Col>
      </Row>
      <Row style="margin-top: 10px;">
        <i-Col span="2"
               style="margin-top: 5px;margin-left: 5px;text-align:right">身份证号：</i-Col>
        <i-Col span="9">
          <Input v-model="Id_no"
                 placeholder="请输入身份证号"
                 style="width: 500px" />
          <span class="red">*</span>
        </i-Col>
        <i-Col span="3"
               style="margin-top: 5px;margin-left: 5px;text-align:right">护照号：</i-Col>
        <i-Col span="9"><Input v-model="passport_no"
                 placeholder="请输入护照号"
                 style="width: 500px" /></i-Col>
      </Row>
      <Row style="margin-top: 10px;">
        <i-Col span="2"
               style="margin-top: 5px;margin-left: 5px;text-align:right">性别：</i-Col>
        <i-Col span="9">
          <!--<Input v-model="sex" placeholder="请输入性别" style="width: 500px" />-->
          <Select v-model="sex"
                  style="width:500px">
            <Option :value=item.value
                    v-for="item in genderData"
                    :key="item.value">{{item.label}}</Option>
          </Select>
          <span class="red">*</span>
        </i-Col>
        <i-Col span="3"
               style="margin-top: 5px;margin-left: 5px;text-align:right">手机号：</i-Col>
        <i-Col span="9"><Input v-model="tel"
                 placeholder="请输入手机号"
                 style="width: 500px" /></i-Col>
      </Row>

      <Row style="margin-top: 10px;">
        <i-Col span="2"
               style="margin-top: 5px;margin-left: 5px;text-align:right">所属省：</i-Col>
        <i-Col span="9"><Input v-model="province"
                 placeholder="请输入所属省"
                 style="width: 500px" /></i-Col>
        <i-Col span="3"
               style="margin-top: 5px;margin-left: 5px;text-align:right">所属市：</i-Col>
        <i-Col span="9"><Input v-model="city"
                 placeholder="请输入所属市"
                 style="width: 500px" /></i-Col>
      </Row>
      <Row style="margin-top: 10px">
        <i-Col span="2"
               style="margin-top: 5px;margin-left: 5px;text-align:right">所属区县：</i-Col>
        <i-Col span="9"><Input v-model="countya"
                 placeholder="请输入所属区县"
                 style="width: 500px" /></i-Col>
        <i-Col span="3"
               style="margin-top: 5px;margin-left: 5px;text-align:right">人群分类：</i-Col>
        <i-Col span="9"><Input v-model="pop_type"
                 placeholder="请输入人群分类"
                 style="width: 500px" /></i-Col>
      </Row>
      <Row style="margin-top: 10px">
        <i-Col span="2"
               style="margin-top: 5px;margin-left: 5px;text-align:right">病例分类：</i-Col>
        <i-Col span="9">
          <!-- <Input v-model="case_type" placeholder="请输入病例分类" style="width: 500px" />-->
          <Select v-model="case_type"
                  style="width:500px">
            <Option :value=item.value
                    v-for="item in blfenle"
                    :key="item.value">{{item.label}}</Option>
          </Select>
          <span class="red">*</span>
        </i-Col>
        <i-Col span="3"
               style="margin-top: 5px;margin-left: 5px;text-align:right">发病日期：</i-Col>
        <i-Col span="9">
          <!-- <Input v-model="onset_day" placeholder="请输入发病日期" style="width: 500px" />-->
          <DatePicker type="date"
                      v-model="onset_day"
                      style="width: 500px"
                      placeholder="请选择发病日期"></DatePicker>
          <span class="red">*</span>
        </i-Col>
      </Row>
      <Row style="margin-top: 10px">
        <i-Col span="2"
               style="margin-top: 5px;margin-left: 5px;text-align:right">诊断时间：</i-Col>
        <i-Col span="9">
          <!--   <Input v-model="diagnostic_time" placeholder="请输入诊断时间" style="width: 500px" />-->
          <DatePicker type="date"
                      v-model="diagnostic_time"
                      style="width: 500px"
                      placeholder="请选择诊断时间"></DatePicker>
          <span class="red">*</span>
        </i-Col>
        <i-Col span="3"
               style="margin-top: 5px;margin-left: 5px;text-align:right">收治医院：</i-Col>
        <i-Col span="9"><Input v-model="admitted_hospital"
                 placeholder="请输入收治医院"
                 style="width: 500px" /></i-Col>
      </Row>
      <Row style="margin-top: 10px">
        <i-Col span="2"
               style="margin-top: 5px;margin-left: 5px;text-align:right">入院时间：</i-Col>
        <i-Col span="9">
          <!--<Input v-model="admission_time" placeholder="请输入入院时间" style="width: 500px" />-->
          <DatePicker type="date"
                      v-model="admission_time"
                      style="width: 500px"
                      placeholder="请选择入院时间"></DatePicker>
          <span class="red">*</span>
        </i-Col>
        <i-Col span="3"
               style="margin-top: 5px;margin-left: 5px;text-align:right">临床严重程度：</i-Col>
        <i-Col span="9">
          <!-- <Input v-model="clinical_severity" placeholder="请输入临床严重程度" style="width: 500px" />-->
          <Select v-model="clinical_severity"
                  style="width:500px">
            <Option :value=item.value
                    v-for="item in linchuangyz"
                    :key="item.value">{{item.label}}</Option>
          </Select>
          <span class="red">*</span>
        </i-Col>
      </Row>
      <Row style="margin-top: 10px">
        <i-Col span="2"
               style="margin-top: 5px;margin-left: 5px;text-align:right">治愈出院日期：</i-Col>
        <i-Col span="9">
          <!--<Input v-model="cure_date" placeholder="请输入治愈出院日期" style="width: 500px" />-->
          <DatePicker type="date"
                      v-model="cure_date"
                      style="width: 500px"
                      placeholder="请选择治愈出院日期"></DatePicker>
        </i-Col>
        <i-Col span="3"
               style="margin-top: 5px;margin-left: 5px;text-align:right">解除隔离日期：</i-Col>
        <i-Col span="9">
          <!-- <Input v-model="Isolation_release_date" placeholder="请输入解除隔离日期" style="width: 500px" />-->
          <DatePicker type="date"
                      v-model="Isolation_release_date"
                      style="width: 500px"
                      placeholder="请选择解除隔离日期"></DatePicker>
        </i-Col>
      </Row>
      <Row style="margin-top: 10px">
        <i-Col span="2"
               style="margin-top: 5px;margin-left: 5px;text-align:right">是否输入病例：</i-Col>
        <i-Col span="9">
          <!-- <Input v-model="Input_case" placeholder="是否输入病例" style="width: 500px" />-->
          <Select v-model="Input_case"
                  style="width:500px">
            <Option :value=item.value
                    v-for="item in ifbingli"
                    :key="item.value">{{item.label}}</Option>
          </Select>
          <span class="red">*</span>
        </i-Col>
        <i-Col span="3"
               style="margin-top: 5px;margin-left: 5px;text-align:right">入境前居住或旅行的国家或地区：</i-Col>
        <i-Col span="9"><Input v-model="before_entry"
                 placeholder="入境前居住或旅行的国家或地区"
                 style="width: 500px" /></i-Col>
      </Row>
      <div slot="footer"
           style="text-align: right">
        <Button type="primary"
                @click="okb">确定</Button>
        <Button @click="cancelb">关闭</Button>
      </div>
    </Modal>
    <Modal width="1100px"
           v-model="tian"
           title="添加"
           @on-ok="ok"
           @on-cancel="tian===false">
      <Row>
        <i-Col span="2"
               style="margin-top: 5px;margin-left: 5px;text-align:right">区县市：</i-Col>
        <i-Col span="9">
          <Select v-model="quxian"
                  style="width:50%">
            <Option :value=item.name
                    v-for="item in areaList"
                    :key="item.name">{{item.name}}</Option>
          </Select>
        </i-Col>
        <i-Col span="3"
               style="margin-top: 5px;margin-left: 5px;text-align:right">单位：</i-Col>
        <i-Col span="9"><Input v-model="danwei"
                 style="width: 200px" /></i-Col>
      </Row>
      <Row style="margin-top: 10px;">
        <i-Col span="2"
               style="margin-top: 5px;margin-left: 5px;text-align:right">房间总数：</i-Col>
        <i-Col span="9"><Input v-model="fangjianzong"
                 style="width: 200px" /></i-Col>
        <i-Col span="3"
               style="margin-top: 5px;margin-left: 5px;text-align:right">正在使用房间数：</i-Col>
        <i-Col span="9"><Input v-model="fangjianing"
                 style="width: 200px" /></i-Col>
      </Row>
      <Row style="margin-top: 10px">
        <i-Col span="2"
               style="margin-top: 5px;margin-left: 5px;text-align:right">管理人员：</i-Col>
        <i-Col span="9"><Input v-model="guanliren"
                 style="width: 200px" /></i-Col>
        <i-Col span="3"
               style="margin-top: 5px;margin-left: 5px;text-align:right">管理人员数：</i-Col>
        <i-Col span="9"><Input v-model="guanlirenshu"
                 style="width: 200px" /></i-Col>
      </Row>
      <Row style="margin-top: 10px">
        <i-Col span="2"
               style="margin-top: 5px;margin-left: 5px;text-align:right">维护房间数：</i-Col>
        <i-Col span="9"><Input v-model="weihufangjian"
                 style="width: 200px"
                 readonly /></i-Col>
        <i-Col span="3"
               style="margin-top: 5px;margin-left: 5px;text-align:right">可接纳房间数：</i-Col>
        <i-Col span="9"><Input v-model="jienafangjian"
                 style="width: 200px"
                 @on-blur="jisuan" /></i-Col>
      </Row>
      <Row style="margin-top: 10px">
        <i-Col span="2"
               style="margin-top: 5px;margin-left: 5px;text-align:right">状态：</i-Col>
        <i-Col span="9">
          <RadioGroup v-model="btn">
            <Radio :value=item.value
                   v-for="item in anniu"
                   :key="item.value"
                   :label="item.value">{{item.lable}}</Radio>
          </RadioGroup>
        </i-Col>
        <!--            <i-Col span="3" style="margin-top: 5px;margin-left: 5px;text-align:right">单位：</i-Col>-->
        <!--            <i-Col span="9"><Input v-model="value" placeholder="Enter something..." style="width: 200px" /></i-Col>-->
      </Row>
    </Modal>
  </div>
</template>

<script>

import areaJSON from '@/libs/area'
import { createqzry, date2str, insertfindglbgCounty, insetgequ } from '@/api/statistics-data-list'

export default {

  name: 'dlqsearch',
  props: {
    typea: {
      type: String,
      default: () => {
        return ''
      }
    },
    aa: {
      type: String,
      default: () => {
        return ''
      }
    },
    areaName: {
      type: String,
      default: () => {
        return ''
      }
    },
    searchType: {
      type: String,
      default: () => {
        return ''
      }
    },
    searchMore: {
      type: String,
      default: () => {
        return ''
      }
    }
  },

  data () {
    return {
      start_time: '',
      end_time: '',
      tian: false,
      genderData: [
        {
          value: '男',
          label: '男'
        },
        {
          value: '女',
          label: '女'
        }
      ],
      ifbingli: [
        {
          value: '是',
          label: '是'
        },
        {
          value: '否',
          label: '否'
        }
      ],
      blfenle: [
        {
          value: '阳性检测',
          label: '阳性检测'
        },
        {
          value: '确诊病例',
          label: '确诊病例'
        }
      ],
      linchuangyz: [
        {
          value: '无症状感染者',
          label: '无症状感染者'
        },
        {
          value: '普通型',
          label: '普通型'
        },
        {
          value: '重型',
          label: '重型'
        }
      ],
      anniu: [{ lable: '停用', value: '1' }, { lable: '启动', value: '0' }],
      btn: '',
      county: '',
      guanlirenshu: '',
      guanliren: '',
      jienafangjian: '',
      weihufangjian: '',
      fangjianing: '',
      fangjianzong: '',
      quxian: '',
      type: '',
      danwei: '',
      name: '',
      Id_no: '',
      passport_no: '',
      sex: '',
      tel: '',
      nationality: '',
      province: '',
      city: '',
      countya: '',
      pop_type: '',
      case_type: '',
      onset_day: '',
      diagnostic_time: '',
      admitted_hospital: '',
      admission_time: '',
      clinical_severity: '',
      Input_case: '',
      before_entry: '',
      cure_date: '',
      Isolation_release_date: '',
      modalb: false,
      searchObj: {
        key: ''
      },
      indeterminate: true,
      checkAll: false,

      areaList: areaJSON,

      countryList: []

    }
  },

  components: {

  },

  computed: {

  },

  methods: {
    timeChange (time) {
      this.start_time = time[0]
      this.end_time = time[1]
    },
    cancelb () {
      this.name = ''// 清空弹框的输入框默认值
      this.Id_no = ''
      this.passport_no = ''
      this.sex = ''
      this.tel = ''
      this.nationality = ''
      this.province = ''
      this.city = ''
      this.countya = ''
      this.pop_type = ''
      this.case_type = ''
      this.onset_day = ''
      this.diagnostic_time = ''
      this.admitted_hospital = ''
      this.admission_time = ''
      this.clinical_severity = ''
      this.Input_case = ''
      this.before_entry = ''
      this.cure_date = ''
      this.Isolation_release_date = ''
      this.modalb = false
    },
    okb () {
      this.onset_day = date2str(this.onset_day)// 发病日期
      this.diagnostic_time = date2str(this.diagnostic_time)// 诊断时间
      this.admission_time = date2str(this.admission_time)// 入院时间
      this.cure_date = date2str(this.cure_date)
      this.Isolation_release_date = date2str(this.Isolation_release_date)
      console.log(this.onset_day, '日期')
      if (!this.name) {
        this.$Notice.error({ title: '请填写姓名', desc: '' })
        return false
      } else if (!this.sex) {
        this.$Notice.error({ title: '请选择性别', desc: '' })
        return false
      } else if (!this.Id_no) {
        this.$Notice.error({ title: '请填写身份证号', desc: '' })
        return false
      } else if (!this.case_type) {
        this.$Notice.error({ title: '请选择病例类别', desc: '' })
        return false
      } else if (!this.Input_case) {
        this.$Notice.error({ title: '请选择是否输入病例', desc: '' })
        return false
      } else if (!this.clinical_severity) {
        this.$Notice.error({ title: '请选择临床严重程度', desc: '' })
        return false
      } else if (!this.onset_day) {
        this.$Notice.error({ title: '请选择发病日期', desc: '' })
        return false
      } else if (!this.diagnostic_time) {
        this.$Notice.error({ title: '请选择诊断时间', desc: '' })
        return false
      } else if (!this.admission_time) {
        this.$Notice.error({ title: '请选择入院时间', desc: '' })
        return false
      }
      let data = {
        name: this.name,
        Id_no: this.Id_no,
        passport_no: this.passport_no,
        sex: this.sex,
        tel: this.tel,
        nationality: this.nationality,
        province: this.province,
        city: this.city,
        county: this.countya,
        pop_type: this.pop_type,
        case_type: this.case_type,
        onset_day: this.onset_day,
        diagnostic_time: this.diagnostic_time,
        admitted_hospital: this.admitted_hospital,
        admission_time: this.admission_time,
        clinical_severity: this.clinical_severity,
        Input_case: this.Input_case,
        before_entry: this.before_entry,
        cure_date: this.cure_date,
        Isolation_release_date: this.Isolation_release_date
      }
      createqzry(data).then(ret => {
        if (ret.data.errmsg === 'success') {
          this.$Message.success('添加成功')
          this.modalb = false
          let a = { type: '确诊和无症状 ', classification: '1', address: 'http://124.95.133.9:80/api/us/yiqing/yqwlryinfo/insetgequ' }
          insetgequ(a).then(res => {

          })
        }
      })
    },
    apenda () {
      this.modalb = true
      this.name = ''// 清空弹框的输入框默认值
      this.Id_no = ''
      this.passport_no = ''
      this.sex = ''
      this.tel = ''
      this.nationality = ''
      this.province = ''
      this.city = ''
      this.countya = ''
      this.pop_type = ''
      this.case_type = ''
      this.onset_day = ''
      this.diagnostic_time = ''
      this.admitted_hospital = ''
      this.admission_time = ''
      this.clinical_severity = ''
      this.Input_case = ''
      this.before_entry = ''
      this.cure_date = ''
      this.Isolation_release_date = ''
    },
    ok () {
      let data = {
        num_info: this.guanliren,
        num_gl: this.guanlirenshu,
        county: this.quxian,
        company: this.danwei,
        zs: this.fangjianzong,
        num_sy: this.fangjianing,
        num_ky: this.jienafangjian,
        num_wh: this.weihufangjian,
        type: this.btn
      }
      console.log(
        this.btn, '按钮'
      )
      insertfindglbgCounty(data).then(ret => {
        let a = { type: '隔离宾馆 ', classification: '2', address: 'http://124.95.133.9:80/api/us/yiqing/yqwlryinfo/insetgequ' }
        insetgequ(a).then(res => {

        })
      })
      this.tian = false
    },
    jisuan () {
      this.weihufangjian = this.fangjianzong - this.fangjianing - this.jienafangjian
    },
    tianjia () {
      this.tian = true
      console.log(this.areaList, 111)
    },
    searchMoreAcion () {
      this.$emit('search', {
        key: this.searchObj.key,
        county: this.county,
        searchMore: 'searchMore'
      })
    },
    async init () {

    },
    handleCheckAll () {
      if (this.indeterminate) {
        this.checkAll = false
      } else {
        this.checkAll = !this.checkAll
      }
      this.indeterminate = false

      if (this.checkAll === true) {
        this.countryList = ['市本级', '和平区', '沈河区', '铁西区', '皇姑区', '大东区', '浑南区', '于洪区', '沈北新区', '苏家屯区', '辽中区', '新民市', '法库县', '康平县']
      } else {
        this.countryList = []
      }
      this.changeCountry(this.countryList)
    },

    search () {
      console.log(this.countryList, '市级')
      this.$emit('search', {
        key: this.searchObj.key,
        start_time: this.start_time,
        end_time: this.end_time,
        county: this.county
      })
    },

    changeCountry (val) {
      console.log(val.length, '111111111111111')
      console.log(this.areaName, '点击')
      console.log(val)
      // if (val.length === 13) {
      //   this.$emit('search', {
      //     key: this.searchObj.key
      //   })
      // } else {
      //   this.county = val.join(',')
      //   this.$emit('search', {
      //     key: this.searchObj.key,
      //     county: this.county
      //   })
      // }
      this.county = val.join(',')
      this.$emit('search', {
        key: this.searchObj.key,
        county: this.county
      })
    }
  },

  watch: {
    areaName (data) {
      if (data) {
        this.countryList.push(data)
        console.log(this.countryList)
        let list = this.countryList.join(',')
        console.log(list, '1111')
        this.$emit('search', {
          key: this.searchObj.key,
          county: list
        })
      }
    }
  },

  mounted () {
    this.init()
    if (this.areaName !== '' && this.areaName !== undefined && this.areaName !== null) {
      this.changeCountry(this.areaName)
    }
  }

}
</script>

<style scoped>
.dlqsearch >>> .ivu-form-item {
  margin-bottom: 0;
}
.red {
  color: red;
}
</style>
